<%@ include file="/mc/common/charset.jsp" %>

<html>
<script language="JavaScript">

   // Trim whitespace from left and right sides of s.
    function trim(s) {
      return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }
  
  //
  // Trims leading blanks.
  //
  function stringLeftTrim(s) {
    return s.replace(/^ +/, "");
  }
  
  //
  // Trims trailing blanks.
  //
  function stringRightTrim(s) {
    return s.replace(/ +$/, "");
  }
  
  //
  // Trims leading and trailing blanks.
  //
  function stringTrim(s) {
    return stringRightTrim(stringLeftTrim(s));
  }
  
  //
  // Create a dummy (timestamp) attribute to get around an IE cache problem.
  //
  function getTimeStamp() {
     var now = new Date;
     var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
     return timestamp;
  }
  
  function doSubmit() {
   searchUserPopup("<%=request.getParameter("parentFormName")%>","<%=request.getParameter("parentFieldName")%>");
  }
  
  function searchUserPopup(parentFormName, parentFieldName) {

      var timestamp = getTimeStamp();
       var thisForm = window.opener.document.forms[parentFormName];
       var dummyForm=document.forms["DummyForm"];
       if (parentFieldName == "from") {
        var userAliasFrom = stringTrim(thisForm.userAliasFrom.value);
        dummyForm.userAlias.value=userAliasFrom;
         if (thisForm.useFullName.value == "true") {
          var fullNameFrom = stringTrim(thisForm.fullNameFrom.value);
          dummyForm.fullName.value=fullNameFrom;
           if ((userAliasFrom != "") || (fullNameFrom != "")) {
             dummyForm.executeSearch.value="true";
          }
        }
        else {
          var firstNameFrom = stringTrim(thisForm.firstNameFrom.value);
          var lastNameFrom = stringTrim(thisForm.lastNameFrom.value);
          dummyForm.firstName.value=firstNameFrom;
          dummyForm.lastName.value=lastNameFrom;
          if ((userAliasFrom != "") || (firstNameFrom != "") ||
    (lastNameFrom != "")) {
                  dummyForm.executeSearch.value="true";
          }
        }
      }
      else {
        var userAliasTo = stringTrim(thisForm.userAliasTo.value);
        dummyForm.userAlias.value=userAliasTo;
        if (thisForm.useFullName.value == "true") {
          var fullNameTo = stringTrim(thisForm.fullNameTo.value);
          dummyForm.fullName.value=fullNameTo;
          if ((userAliasTo != "") || (fullNameTo != "")) {
            dummyForm.executeSearch.value="true";
          }
        }
        else {
          var firstNameTo = stringTrim(thisForm.firstNameTo.value);
          var lastNameTo = stringTrim(thisForm.lastNameTo.value);
           dummyForm.firstName.value=firstNameTo;
          dummyForm.lastName.value=lastNameTo;
          if ((userAliasTo != "") || (firstNameTo != "") || (lastNameTo != "")) {
            dummyForm.executeSearch.value="true";
          }
        }
       
    }
    dummyForm.parentFormName.value=parentFormName;
    dummyForm.parentFieldName.value=parentFieldName;    
    dummyForm.action="<%=request.getContextPath()%>/mt/userSearchPopup.do";
    dummyForm.method="post";
    dummyForm.submit();
    }

 
</script>
<body onload="doSubmit();">
</body>
<form name="DummyForm" method="post" action="/mt/userSearchPopup.do">
<input type="hidden" name="firstName" />
<input type="hidden" name="lastName" />
<input type="hidden" name="userAlias" />
<input type="hidden" name="fullName" />
<input type="hidden" name="executeSearch" />
<input type="hidden" name="parentFormName" />
<input type="hidden" name="parentFieldName" />
</form>

</html>
